#ifndef FG_WORLDNET_CLIENT_MODULE_H
#define FG_WORLDNET_CLIENT_MODULE_H

#include "Protocol/Protocol.h"
#include "PluginModule/IWorldToMasterModule.h"
//#include "Common/Interface/IWorldLogicModule.h"
#include "PluginModule/INetModule.h"
//#include "Common/Interface/IClassModule.h"
//#include "Common/Interface/IElementModule.h"
#include "PluginModule/IConfigModule.h"
#include "PluginModule/ILogModule.h"
#include "PluginModule/IWorldNetServerModule.h"
#include "PluginModule/INetClientModule.h"
#include "PluginModule/ISecurityModule.h"

namespace FragrantGrass
{
	class WorldToMasterModule
		: public IWorldToMasterModule
	{
	public:
		WorldToMasterModule(IPluginManager* p)
		{
			m_pPluginManager = p;
			mLastReportTime = 0;
		}

		virtual bool Init();
		virtual bool BeforeShut();
		virtual bool Shut();
		virtual bool Execute();
		virtual bool AfterInit();

	protected:

		void OnSocketMSEvent(const SOCK nSockIndex, const FG_NET_EVENT eEvent, INet* pNet);

		void OnClientDisconnect(const SOCK nAddress);

		void OnClientConnected(const SOCK nAddress);

		virtual void LogServerInfo(const std::string& strServerInfo);


		void Register(INet* pNet);
		void ServerReport();
		void RefreshWorldInfo();
		void OnServerInfoProcess(const SOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);

		void OnSelectServerProcess(const SOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
		void OnKickClientProcess(const SOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);

		void InvalidMessage(const SOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
	private:
		INT64 mLastReportTime;

		ILogModule* m_pLogModule;
		IWorldNetServerModule* m_pWorldNetServerModule;
		INetClientModule* m_pNetClientModule;
		INetModule* m_pNetModule;
		ISecurityModule* m_pSecurityModule;
		IConfigModule* m_pConfigModule;
	};
}

#endif